package controller;

import entity.hotel_employee;
import service.HotelEmployeeService;
import serviceImp.HotelEmployeeServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Servlet implementation class EmployeeInfoController
 */
@WebServlet("/employee/EmployeeDeleteController.do")
public class EmployeeDeleteController extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmployeeDeleteController() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");

		String employee_tel = request.getParameter("employee_tel");
		String deleteTel = request.getParameter("deleteTel");

		HotelEmployeeService hotelEmployeeService = new HotelEmployeeServiceImp();

		if(deleteTel!=null){
			int code = hotelEmployeeService.deleteByTel(deleteTel);
			if(code>0){
				request.setAttribute("deleteTip","成功删除");
				request.getRequestDispatcher("/employee/employeeDelete.jsp").forward(request,response);
			}
		}

		hotel_employee hotel_employee = hotelEmployeeService.selectInfoByTel(employee_tel);
		if(hotel_employee!=null){
			request.setAttribute("hotel_employee",hotel_employee);
			request.getRequestDispatcher("/employee/employeeDelete.jsp").forward(request,response);
		}else {
			request.setAttribute("deleteTip","查无此人，请重新输入");
			request.getRequestDispatcher("/employee/employeeDelete.jsp").forward(request,response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
